import Vue from 'vue'
//公共通讯调用
let ajaxUtil = {
  servUrl: 'http://127.0.0.1:8081/api/v1',
  get(api, param) {
    let paramstr = ''
    if (param) {
      for (let key in param)
        paramstr += ((paramstr.length == 0 ? "?" : "&") + (key + "=" + param[key]))
    }
    let turl = this.servUrl + api + paramstr
    return Vue.http.get(turl)
  },
  post(api, param) {
    let url = this.servUrl + api
    return Vue.http.post(url, param)
  },
  resource(api) {
    //resource支持的方法
    // get: {method: 'GET'}, 
    // save: {method: 'POST'}, 
    // query: {method: 'GET'}, 
    // update: {method: 'PUT'}, 
    // remove: {method: 'DELETE'}, 
    // delete: {method: 'DELETE'}
    let url = this.servUrl + api
    return Vue.resource(url)
  }
}

export default ajaxUtil